﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using Wekit.Web.Models;
using Wekit.Web.Security;
using System.Web;
namespace Wekit.Controllers.Website
{
    public class AuthController : Controller
    {
        /// <summary>
        /// 表单认证服务类
        /// </summary>
        public IFormsAuthenticationService FormsAuthenticationService { get; set; } 


        /// <summary>
        /// 登录首页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return RedirectToAction("LogOn");
        }

        /// <summary>
        /// 获取登录页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult LogOn()
        {
            return View();
        }

        /// <summary>
        /// 普通用户登录函数
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult LogOn(LogOnModel logOnModel)
        {
            
            FormsAuthenticationService.SignIn(logOnModel.UserId, false);
            AuthIdentity identity = new AuthIdentity();
            
            AuthUser user = new AuthUser();
            identity.Name = logOnModel.UserId+"dfsafdsa";
            identity.IsAuthenticated = true;
            identity.AuthenticationType = HttpContext.User.Identity.AuthenticationType;
            user.Identity = identity;
          
            HttpContext.User = user;
            return Redirect("/Website");
        }


        /// <summary>
        /// 普通用户登出函数
        /// </summary>
        /// <returns></returns>
        public ActionResult LogOut()
        {
            FormsAuthenticationService.SignOut();
            return RedirectToAction("Index","Home");
        }
    }
}
